package com.ftwj.utils.result;

import com.baomidou.mybatisplus.core.toolkit.EncryptUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

public class ResultBean<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;
    private String message;
    private Object data;

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getData() {
        return data;
    }

    private ResultBean() {
        super();
    }

    private ResultBean(MessageEnum message) {
        this.code = message.getCode();
        this.message = message.getMessage();
    }

    private ResultBean(MessageEnum message, Object data) {
        this.code = message.getCode();
        this.message = message.getMessage();
        this.data = data;
    }

    public ResultBean(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultBean(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResultBean<T> success(Integer code, String message) {
        return new ResultBean<T>(code, message);
    }

    public static <T> ResultBean<T> success() {
        return new ResultBean<T>(MessageEnum.HANDLE_SUCCESS);
    }

    public static <T> ResultBean<T> success( T data) {
        return new ResultBean<T>(MessageEnum.HANDLE_SUCCESS, data);
    }


    /**
     * @author Liu_xg
     * @date 2021-7-26 11:36
     * @description: 返回值加密
     */
    public static <T> ResultBean<T> encryptData(HttpServletRequest request,
                                                Integer code,
                                                String massage, T data) {
        return new ResultBean<T>(MessageEnum.HANDLE_SUCCESS, data);
    }

    public static <T> ResultBean<T> error(MessageEnum massage) {
        return new ResultBean<T>(massage, null);
    }


    public static <T> ResultBean<T> error(HttpServletRequest request, Integer code, String massage) {
        return new ResultBean<T>(code, massage);
    }

    public static <T> ResultBean<T> error(Integer code, String massage) {
        return new ResultBean<T>(code, massage);
    }

}
